// component/unfinished/index.ts
import { orderList,orderListGJ } from '../../api/order'
Component({

  /**
   * 组件的属性列表
   */
  properties: {
    userID:{
      type:Number,
    },
    comID:{
      type:Number,
    },
    day:{
      type:String,
    },
    teday:{
      type:String
    },
    history:{
      type:String
    }
  },
  observers:{
    'userID':function(newVal){
      const type = this.data.tabsName
      const comID = this.properties.comID;
      const userID = this.properties.userID;
      const identity = wx.getStorageSync("userInfo").data.position
      if(identity=='管家'){
        orderListGJ(comID, userID, type, '0').then((res: any) => {
          if (res.data.code == 200) this.setData({ dataList: res.data.data, isFresh: false })
          // console.log(this.data.dataList)
        })
      }else{
        orderList(comID, userID, type, '0').then((res: any) => {
          if (res.data.code == 200) this.setData({ dataList: res.data.data, isFresh: false })
          // console.log(this.data.dataList)
        })
      }


    }
  },
  /**
   * 组件的初始数据
   */
  data: {
    tabsName: '1',
    comID:-1,
    userID:-1,
    dataList:[],
    isFresh:false,
    identity:""

  },

  /**
   * 组件的方法列表
   */
  methods: {
    handleTabs(e: any) {
      this.setData({
        tabsName: e.detail.name
      })
      switch (e.detail.name) {
        case '1':
          this.getInfo('1');
          break;
        case '2':
          this.getInfo('2');
          break;
        case '3':
          this.getInfo('3');
          break;
      }
    },
    getInfo(type: string) {
      const comID = this.properties.comID;
      const userID = this.properties.userID;
      const identity = wx.getStorageSync("userInfo").data.position
      if(identity=='管家'){
        orderListGJ(comID, userID, type, '0').then((res: any) => {
          if (res.data.code == 200) this.setData({ dataList: res.data.data, isFresh: false })
          console.log(this.data.dataList)
        })
      }else{
        orderList(comID, userID, type, '0').then((res: any) => {
          if (res.data.code == 200) this.setData({ dataList: res.data.data, isFresh: false })
          console.log(this.data.dataList)
        })
      }
    },
    fresh(){
      this.setData({
          isFresh:true
      })
      this.triggerEvent('getSum')
      switch (this.data.tabsName) {
        case '1':
          this.getInfo('1');
          break;
        case '2':
          this.getInfo('2');
          break;
        case '3':
          this.getInfo('3');
          break;
      }
    },

  },
  //小程序声明周期
  lifetimes: {
    attached: function () {
      // 在组件实例进入页面节点树时执行
    },
    detached: function () {
      // 在组件实例被从页面节点树移除时执行
    },
    moved:function(){
    }
  },
  pageLifetimes: {
    show: function () {
      this.setData({
        identity:wx.getStorageSync("userInfo").data.position
      })
      // 页面被展示
      // switch (this.data.tabsName) {
      //   case '1':
      //     this.getInfo('1');
      //     break;
      //   case '2':
      //     this.getInfo('2');
      //     break;
      //   case '3':
      //     this.getInfo('3');
      //     break;
      // }
    },
    hide: function () {
      // 页面被隐藏
    },
    resize: function () {
      // 页面尺寸变化
     
    }
  }
})